﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using MVCms.Core.DataAccess;
using MVCms.Core.Developers;

namespace MVCms.Core.Entities
{
    /// <summary>
    /// Page Role
    /// </summary>
    public class PageRole : BaseEntity
    {
        /// <summary>
        /// Gets or sets the role.
        /// </summary>
        /// <value>The role.</value>
        public virtual string Role { get; set; }
        /// <summary>
        /// Gets or sets the page.
        /// </summary>
        /// <value>The virtual page.</value>
        public virtual VirtualPage VirtualPage { get; set; }
        /// <summary>
        /// Gets a list of users that's allowed to view the page
        /// </summary>
        /// <value>The users.</value>
        [McContext.IgnoreAttribute]
        public virtual IList<MembershipUser> Users
        {
            get
            {
                return Roles.GetUsersInRole(this.Role).Select(username => Membership.GetUser(username, false)).ToList();
            }
        }
    }

    /// <summary>
    /// Module Role
    /// </summary>
    public class ModuleRole : BaseEntity
    {
        /// <summary>
        /// Gets or sets the role.
        /// </summary>
        /// <value>The role.</value>
        public virtual string Role { get; set; }
        /// <summary>
        /// Gets or sets the page module.
        /// </summary>
        /// <value>The page module.</value>
        public virtual PageModule PageModule { get; set; }
        /// <summary>
        /// Gets a list of users that's allowed to view the module
        /// </summary>
        /// <value>The users.</value>
        [McContext.IgnoreAttribute]
        public virtual IList<MembershipUser> Users
        {
            get
            {
                return Roles.GetUsersInRole(this.Role).Select(username => Membership.GetUser(username, false)).ToList();
            }
        }
    }
}
